package JDBC.model;

import org.apache.commons.dbcp.BasicDataSource;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.object.SqlFunction;

/**
 * @Fou Jack of all trades and master of none.
 * @date 2022/1/6 17:07
 */
public class UserSqlFunction {
    //使用SqlFunction返回单一行的查询结果，默认返回int
   @org.junit.Test
    public void SqlFunction(){
        ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"SqlUpdate.xml"});
        BeanFactory factory = context;
        BasicDataSource dataSource = (BasicDataSource) factory.getBean("datasource");
        SqlFunction sf = new SqlFunction(dataSource,"select count(1) from t_user;");
        sf.compile();
        int count=sf.run();
        System.out.println("User Count(统计的用户总数):" +count);

    }
}
